package com.ocean.web.controller.product;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.productDict.domain.OForecastElement;
import com.ocean.productDict.service.IOForecastElementService;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 要素维护Controller
 *
 * @author ocean
 * @date 2023-01-03
 */
@Controller
@RequestMapping("/product/forecastElement")
public class OForecastElementController extends BaseController
{
    private String prefix = "product/forecastElement";

    @Autowired
    private IOForecastElementService oForecastElementService;

    //@RequiresPermissions("product:forecastElement:view")
    @GetMapping()
    public String forecastElement()
    {
        return prefix + "/list";
    }

    /**
     * 查询要素维护列表
     */
    //@RequiresPermissions("product:forecastElement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OForecastElement oForecastElement)
    {
        startPage();
        List<OForecastElement> list = oForecastElementService.selectOForecastElementList(oForecastElement);
        return getDataTable(list);
    }

    /**
     * 导出要素维护列表
     */
   // @RequiresPermissions("product:forecastElement:export")
    @Log(title = "要素维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OForecastElement oForecastElement)
    {
        List<OForecastElement> list = oForecastElementService.selectOForecastElementList(oForecastElement);
        ExcelUtil<OForecastElement> util = new ExcelUtil<OForecastElement>(OForecastElement.class);
        return util.exportExcel(list, "要素维护数据");
    }

    /**
     * 新增要素维护
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        Map<String,List> map = oForecastElementService.getNameAndCode();
        mmap.putAll(map);
        return prefix + "/add";
    }

    /**
     * 新增保存要素维护
     */
    //@RequiresPermissions("product:forecastElement:add")
    @Log(title = "要素维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OForecastElement oForecastElement)
    {
        return toAjax(oForecastElementService.insertOForecastElement(oForecastElement));
    }

    /**
     * 修改要素维护
     */
    //@RequiresPermissions("product:forecastElement:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OForecastElement oForecastElement = oForecastElementService.selectOForecastElementById(id);
        mmap.put("oForecastElement", oForecastElement);
        Map<String,List> map = oForecastElementService.getNameAndCode();
        mmap.putAll(map);
        return prefix + "/edit";
    }

    /**
     * 修改保存要素维护
     */
    //@RequiresPermissions("product:forecastElement:edit")
    @Log(title = "要素维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OForecastElement oForecastElement)
    {
        return toAjax(oForecastElementService.updateOForecastElement(oForecastElement));
    }

    /**
     * 删除要素维护
     */
    //@RequiresPermissions("product:forecastElement:remove")
    @Log(title = "要素维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oForecastElementService.deleteOForecastElementByIds(ids));
    }

    /**
     * 要素维护详情
     */
    //@RequiresPermissions("product:forecastElement:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        OForecastElement oForecastElement = oForecastElementService.selectOForecastElementById(id);
        mmap.put("oForecastElement", oForecastElement);
        return prefix + "/detail";
    }
}
